# @file    : build
# @time    : 2025/3/15
# @author  : yongpeng.yao
# @desc    :
import sys
from subprocess import call


def execute_compiler(file_path, out_path, args=None):
    """
        执行编译
    :param file_path: 要编译的文件名
    :param out_path: 编译输出的文件
    :param args: 编译添加的参数
    :return:
    """

    compiler_command_str = ['gcc', file_path, '-o', out_path, '-lwiringPi']
    if args:
        compiler_command_str.extend(args)
    print(' '.join(compiler_command_str))
    try:
        val = call(compiler_command_str)
    except FileNotFoundError as s:
        print(s.args)
    else:
        print(val)


if __name__ == '__main__':
    file_path_ = sys.argv[1]
    out_path_ = file_path_.replace('.c', '')
    args_ = ['-lpthread']

    execute_compiler(file_path_, out_path_, args_)
